package logic

import (
	"context"
	"github.com/hibiken/asynq"
	"navi-mumbai/app/timer/job/internal/logic/delay"
	"navi-mumbai/app/timer/job/internal/logic/schedule/order"
	"navi-mumbai/app/timer/job/internal/logic/schedule/stat"
	"navi-mumbai/app/timer/job/internal/svc"
	"navi-mumbai/app/timer/job/jobtype"
)

type CronJob struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewCronJob(ctx context.Context, svcCtx *svc.ServiceContext) *CronJob {
	return &CronJob{
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

// register job
func (l *CronJob) Register() *asynq.ServeMux {

	mux := asynq.NewServeMux()

	//scheduler job
	mux.Handle(jobtype.ScheduleUpdateUserLoginDailyStat, stat.NewUpdateUserLoginDailyStatHandler(l.svcCtx))
	mux.Handle(jobtype.ScheduleUpdateUserDepositDailyStat, stat.NewUpdateUserDepositDailyStatHandler(l.svcCtx))
	mux.Handle(jobtype.ScheduleUpdateUserWithdrawDailyStat, stat.NewUpdateUserWithdrawDailyStatHandler(l.svcCtx))
	mux.Handle(jobtype.ScheduleUpdateProvider1GameOrderDailyStat, stat.NewUpdateUserProvider1GameOrderDailyStatHandler(l.svcCtx))
	mux.Handle(jobtype.ScheduleUpdateTodayLtvStat, stat.NewTodayLtvStatHandler(l.svcCtx))
	mux.Handle(jobtype.ScheduleUpdateLastDayLtvStat, stat.NewLastDayLtvStatHandler(l.svcCtx))
	// sync y9y order
	mux.Handle(jobtype.ScheduleSyncGameProviderY9YOrder, order.NewSyncGameProviderY9YOrderHandler(l.svcCtx))
	//defer job
	mux.Handle(jobtype.DeferCheckChatState, delay.NewDeferCheckChatStateHandler(l.svcCtx))

	//queue job , asynq support queue job
	// wait you fill..

	return mux
}
